package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlPortfolioLog entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlPortfolioLog
 * @author MyEclipse Persistence Tools
 */

public class MdlPortfolioLogDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlPortfolioLogDAO.class);
	// property constants
	public static final String USERID = "userid";
	public static final String TIME = "time";
	public static final String PORTFOLIO = "portfolio";
	public static final String CALLER_CLASS = "callerClass";
	public static final String CALLER_FILE = "callerFile";
	public static final String CALLER_SHA1 = "callerSha1";
	public static final String TEMPDATAID = "tempdataid";
	public static final String RETURNURL = "returnurl";
	public static final String CONTINUEURL = "continueurl";

	public void save(MdlPortfolioLog transientInstance) {
		log.debug("saving MdlPortfolioLog instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlPortfolioLog persistentInstance) {
		log.debug("deleting MdlPortfolioLog instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlPortfolioLog findById(java.lang.Long id) {
		log.debug("getting MdlPortfolioLog instance with id: " + id);
		try {
			MdlPortfolioLog instance = (MdlPortfolioLog) getSession().get(
					"idv.loveloser.dao.MdlPortfolioLog", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlPortfolioLog instance) {
		log.debug("finding MdlPortfolioLog instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlPortfolioLog")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlPortfolioLog instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlPortfolioLog as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUserid(Object userid) {
		return findByProperty(USERID, userid);
	}

	public List findByTime(Object time) {
		return findByProperty(TIME, time);
	}

	public List findByPortfolio(Object portfolio) {
		return findByProperty(PORTFOLIO, portfolio);
	}

	public List findByCallerClass(Object callerClass) {
		return findByProperty(CALLER_CLASS, callerClass);
	}

	public List findByCallerFile(Object callerFile) {
		return findByProperty(CALLER_FILE, callerFile);
	}

	public List findByCallerSha1(Object callerSha1) {
		return findByProperty(CALLER_SHA1, callerSha1);
	}

	public List findByTempdataid(Object tempdataid) {
		return findByProperty(TEMPDATAID, tempdataid);
	}

	public List findByReturnurl(Object returnurl) {
		return findByProperty(RETURNURL, returnurl);
	}

	public List findByContinueurl(Object continueurl) {
		return findByProperty(CONTINUEURL, continueurl);
	}

	public List findAll() {
		log.debug("finding all MdlPortfolioLog instances");
		try {
			String queryString = "from MdlPortfolioLog";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlPortfolioLog merge(MdlPortfolioLog detachedInstance) {
		log.debug("merging MdlPortfolioLog instance");
		try {
			MdlPortfolioLog result = (MdlPortfolioLog) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlPortfolioLog instance) {
		log.debug("attaching dirty MdlPortfolioLog instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlPortfolioLog instance) {
		log.debug("attaching clean MdlPortfolioLog instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}